package com.ymatou.iapi.productcategory.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.mongo.BuyerProductWapper;
import com.ymttest.database.mongo.ProductCatalogInfoWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.google.gson.JsonObject;
import com.ymatou.iapi.productcategory.parameter.*;
import com.ymatou.iapi.productcategory.service.*;
/**
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetProductCategoryByCategoryId{
	private static GetProductCategoryByCategoryIdBean GetProductCategoryByCategoryIdBean;
	private static GetProductCategoryByCategoryIdCall GetProductCategoryByCategoryIdCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据规格Id获取商品品类信息");
	}

	@Before
	public void caseUp() {
		GetProductCategoryByCategoryIdBean=new GetProductCategoryByCategoryIdBean();
		//旧站点
//		GetProductCategoryByCategoryIdCall=new GetProductCategoryByCategoryIdCall(EnvSetup.getSystemUrl("productcategory_api"));
		//新站点
		GetProductCategoryByCategoryIdCall=new GetProductCategoryByCategoryIdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(GetProductCategoryByCategoryIdCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCategoryByCategoryId_001() {
		Logger.start(true,"根据规格Id获取商品品类信息");
		try {
			//此接口没有SecondCategoryId RootCategoryId ids用字段
			BuyerProductWapper pcinfow=new BuyerProductWapper();
			//验证10条记录
			List<Map> lm=pcinfow.getProductCategoryInfoLimit(10);
			for (Map m : lm) {
				int cid =Integer.valueOf(m.get("CategoryId").toString());
//				Map rm=pcinfow.getProductCategoryInfoById(m.get("MasterCategoryId").toString());
//				Logger.debug(rm);
				GetProductCategoryByCategoryIdBean.setCategoryId(cid);
				GetProductCategoryByCategoryIdCall.setData(GetProductCategoryByCategoryIdBean);
				GetProductCategoryByCategoryIdCall.callService();			
				Logger.verifyEquals("200", GetProductCategoryByCategoryIdCall.getString("Code"), "验证Code");
				ProductCategoryDto pd=(ProductCategoryDto)FormatUtil.GSONToObject(GetProductCategoryByCategoryIdCall.getData().toString(),ProductCategoryDto.class);
				Logger.verifyEquals(m.get("CategoryEnName"), pd.getCategoryEnName(), "验证CategoryEnName");
				Logger.verifyEquals(m.get("CategoryName"), pd.getCategoryName(), "验证CategoryName");
				Logger.verifyEquals(m.get("CategorySort"), pd.getCategorySort(), "验证CategorySort");
				Logger.verifyEquals(m.get("MasterCategoryId"), pd.getMasterCategoryId(), "验证MasterCategoryId");
				Logger.verifyEquals(m.get("Level"), pd.getLevel(), "验证Level");
				Logger.verifyEquals(m.get("ProductsNum"), pd.getProductsNum(), "验证ProductsNum");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCategoryByCategoryId_002() {
		Logger.start(true,"不输入失败");
		try {
				GetProductCategoryByCategoryIdBean.setCategoryId(null);
				GetProductCategoryByCategoryIdCall.setData(GetProductCategoryByCategoryIdBean);
				GetProductCategoryByCategoryIdCall.callService();			
				Logger.verifyEquals("400", GetProductCategoryByCategoryIdCall.getString("Code"), "验证Code");
				Logger.verifyEquals("null", GetProductCategoryByCategoryIdCall.getJsonObject().getAsJsonObject("Data").get("ProductCategory").toString(), "验证ProductCategory");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductCategoryByCategoryId_003() {
		Logger.start(true,"输入错误参数失败");
		try {
				GetProductCategoryByCategoryIdBean.setCategoryId(null);
				GetProductCategoryByCategoryIdCall.setData(GetProductCategoryByCategoryIdBean);
				GetProductCategoryByCategoryIdCall.callService();			
				Logger.verifyEquals("400", GetProductCategoryByCategoryIdCall.getString("Code"), "验证Code");
				Logger.verifyEquals("null", GetProductCategoryByCategoryIdCall.getJsonObject().getAsJsonObject("Data").get("ProductCategory").toString(), "验证ProductCategory");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}